<?php
/**
 * Nweb Editor
 *
 * This script is protected by copyright. Its use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    source
 * @package     pl.nweb.editor.datatype
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        https://nweb-editor.googlecode.com
 * @link        http://editor.nweb.pl
 */

namespace pl\nweb\editor\datatype\content\attribute;

/**
 * Atrybut, tekst
 *
 * @category    source
 * @package     pl.nweb.editor.datatype
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2012 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
class Text extends \pl\nweb\editor\datatype\content\Attribute
{
    /**
     * Treść atrybutu
     */
    private $_text = '';

    /**
     * Parametry
     */
    const PARAM_TEXT = 'text';

    /**
     * Inicjaliacja obiektu
     *
     * @return void
     */
    protected function _init()
    {
        if($text = $this->_getParam(self::PARAM_TEXT)) {
            $this->_text = $text;
        }
    }

    /**
     * Serializacja obiektu
     *
     * @return string
     */
    public function serialize()
    {
        return $this->_text;
    }

    /**
     * Deserializacja obiektu
     *
     * @param  string $data dane
     * @return void
     */
    public function unserialize($data)
    {
        $this->_text = $data;
    }

    /**
     * Definiuje tekst
     *
     * @param  string $text tekst
     * @return string
     */
    public function setText($text)
    {
        $this->_text = $text;
    }

    /**
     * Zwraca tekst
     *
     * @return string
     */
    public function getText()
    {
        return $this->_text;
    }

    /**
     * Zwraca treść atrybutu
     *
     * @return string
     */
    public function __toString()
    {
        return (string)$this->getText();
    }
}